package server.connector.http;

import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class HttpConnector implements Runnable {
    public void start() {
        new Thread(this).start();
    }
    boolean stop;
    @Override
    public void run() {
        ServerSocket serverSocket = null;
        //服务端套接字创建异常
        try {
            serverSocket = new ServerSocket(Constants.PORT, 1, InetAddress.getByName("127.0.0.1"));
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
        while (!stop) {
            Socket socket;
            //建立连接异常
            try {
                socket = serverSocket.accept();
            } catch (Exception e) {
                continue;
            }
            //处理连接
            new HttpProcessor(this).process(socket);
        }
    }
}
